<template>
  <el-popover placement="right" popper-class="popper-class" :width="100" trigger="hover">
    <template #reference>
      <Icon class="ml-5px" icon="fa:plus-square" style="cursor: pointer" />
    </template>
    <template #default>
      <el-button type="primary" @click="addPendingCall" :disabled="loading">添加到待拨打</el-button>
    </template>
  </el-popover>
</template>

<script setup>
import * as seatingApi from '@/api/call/seating/index'
import { useSoftPhoneStore } from '@/store/modules/softPhone'
import { emitter } from '@/utils/eventBus.ts'

const useSoftPhone = useSoftPhoneStore()
const props = defineProps({
  number: {
    type: String
  },
  source: {
    type: String
  },
  sourceId: {
    type: Number
  },
  sourceName: {
    type: String
  }
})
const loading = ref(false)
/*添加到代拨打*/
const addPendingCall = async () => {
  try {
    loading.value = true
    const data = await seatingApi.createList({
      number: props.number,
      source: props.source,
      sourceId: props.sourceId
    })
    if (data) {
      emitter.emit('add_pending')
      ElMessage.success('添加到待拨打成功!')
    }
  } finally {
    loading.value = false
  }
}
</script>

<style lang="scss" scoped></style>
